import  * as fs from "fs"
import {FileEx} from "./FileEx";

export class Menu {
    //启动的根目录
    static root = process.cwd();

    static init(root: string) {
        Menu.root = root;
        require('source-map-support').install();
        require("./FuncExt");
        require("./ES6Ext");
    }

    static temp = Menu.root + "/runtime/temp/";

    /**
     * 创建缓存目录
     */
    static createTemp() {
        if (!fs.existsSync(Menu.temp)) {
            FileEx.mkdirsSync(Menu.temp)
            for (let i = 1; i <= 31; i++) {
                fs.mkdirSync(Menu.temp + i + "/");
            }
        }
    }

    /**
     * 获取当前缓存目录
     */
    static getTemp() {
        let now = new Date();
        return Menu.temp + now.getDate() + "/";
    }

    /**
     * 清空2天前的缓存
     */
    static clearTemp() {
        let now = new Date();
        now.setDate(now.getDate() - 2)
        FileEx.deleteFolderRecursive(Menu.temp + now.getDate() + "/");
    }
}